Skip to content

Address NRT review feedback and clear remaining warnings - #164

Open
imnasnainaec wants to merge 2 commits into
enable-nrt-corefrom
resolve-nrt-reviews
Open

Address NRT review feedback and clear remaining warnings#164
imnasnainaec wants to merge 2 commits into
enable-nrt-corefrom
resolve-nrt-reviews

Conversation

@imnasnainaec

@imnasnainaec imnasnainaec commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

In place of the long-winded AI-drafted reviews I posted on #157, I offer this pr pr.


This change is Reviewable

- MapToExistingLanguageIfPossible now returns the empty string (not null)
  for empty input, honoring its [return: NotNullIfNotNull] contract.
- Removed the incorrect [MemberNotNullWhen(false, Id, Source, Target)] from
  XLiffTransUnit.IsEmpty: IsEmpty is a conjunction, so !IsEmpty does not
  imply all three members are non-null. Adjusted ToString and
  XLiffBody.AddTransUnitRaw, which relied on that bogus guarantee.
- DefaultInstalledStringFilePath now throws a clear InvalidOperationException
  instead of passing a possibly-null folder to Path.Combine.
- StringCache is backed by a nullable field and throws a clear
  InvalidOperationException instead of being `null!` and NREing when the
  minimal constructor was used.
- MergeXliffDocuments hoists the trans-unit id once per iteration and skips
  units without one, replacing ten null-forgiving `tu.Id!` uses.
- Fixed the four remaining warnings: CS8604 in XLiffBody (hoisted documented
  locals) and CS8618 for DefaultStringFilePath (defaults to string.Empty).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@imnasnainaec
imnasnainaec marked this pull request as ready for review August 31, 2026 19:31
@imnasnainaec
imnasnainaec requested a review from hahn-kev August 31, 2026 19:31

@hahn-kev hahn-kev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to fix the 2 tu.Id! overrides we have as that only holds true if the methods which set the Id never change. I'd opt to throw so we catch the issue early, but if that is highly likely to bubble up to the user then I'd probably avoid that. But we could always just add a test for each that would catch the error in CI.

Comment thread src/L10NSharp/XLiffUtils/XLiffBody.cs Outdated
return;

// GetTransUnitForId returns null for a null id, so existingTu proves tu.Id isn't.
var id = tu.Id!;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works it means that if GetTransUnitForId were to change then this wouldn't work anymore. I say we either throw if id is null, or we return. This is similar to what we do in some places below. Hard to say what the right choice is here, I'd probably throw if this would likely be caught in tests. The same applies to AddTransUnit above.

This comment was marked as outdated.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went a slightly different direction in 9128cec. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants